﻿using Autofac;
using Microsoft.EntityFrameworkCore;
using Model.Models;
using Service;

namespace Demo.Autofac
{
    public class AutomaticInjectionModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
            builder.RegisterType<MyDbContext>().AsSelf().InstancePerLifetimeScope();

            builder.RegisterAssemblyTypes(System.Reflection.Assembly.Load("Service"))
                   .Where(x => x.Name.EndsWith("Service"))
                   .AsImplementedInterfaces();

            var webAssemblytype = typeof(Program).Assembly;
            builder.RegisterAssemblyTypes(webAssemblytype).PropertiesAutowired();

        }
    }
}
